//
//  ViewController.m
//  UI04_事件_触摸_手势
//
//  Created by wyx on 16/3/18.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
#import "ImageViewWithGesture.h"
@interface ViewController ()<UITextFieldDelegate,TouchViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createTouchView];
    [self createGestureView];
    [self createScreenEdgeGesture];
    [self createImageViewWithGesture];
}
#pragma mark - 知识点1:事件
/** 
 * UIEnent类:三种事件: 触摸 晃动 远程控制
 * 本节课重点 触摸
 * 重写 UIResopnder 关于触摸的三个方法
 *
 */
#pragma mark - 知识点2: 触摸事件
- (void)createTouchView{
    TouchView *viewOfRed = [[TouchView alloc] initWithFrame:CGRectMake(20, 50, 300, 60)];
    viewOfRed.backgroundColor = [UIColor redColor];
    [self.view addSubview:viewOfRed];
    [viewOfRed release];
    //输入框
    UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 300, 60)];
    textFiled.backgroundColor  = [UIColor cyanColor];
    textFiled.placeholder = @"请输入用户名";
    textFiled.borderStyle  = 3;
    [self.view addSubview:textFiled];
    [textFiled release];
    //指定协议
    textFiled.delegate = self;
    viewOfRed.delegate = self;
    
}
-(void)didClicked:(TouchView *)touchview{
    self.view.backgroundColor = touchview.backgroundColor;
    
}
#pragma mark - textfiledDelegate 回收键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
/** 点击空白处回收键盘, 重写 touchend方法 */
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesEnded:touches withEvent:event];
    [self.view endEditing:YES];
}
#pragma mark - 知识点3:响应者链
/** 
 * UIView的方法 userIntractionenabled 用户交互
 * UIImageView 用户交互默认是关闭
 * uiLaber
 */
#pragma mark - 知识点4: 手势
- (void)createGestureView{
    UIView *viewOfgesture = [[UIView alloc] initWithFrame:CGRectMake(20, 200, 300, 50)];
    viewOfgesture.backgroundColor = [UIColor blueColor];
    [self.view addSubview:viewOfgesture];
    [viewOfgesture release];
    //创建一个轻拍手势对象
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    //设置相关属性 API
    tap.numberOfTouchesRequired = 1;//手指头数
    tap.numberOfTapsRequired = 1;//轻拍次数
    //添加到相关的视图
    [viewOfgesture addGestureRecognizer:tap];
    [tap release];
}
- (void)handleTap: (UIGravityBehavior *)tap{
    
}
#pragma mark - 知识点5: 自定义 imageView(带手势)
- (void)createImageViewWithGesture{
    ImageViewWithGesture *image = [[ImageViewWithGesture alloc] initWithImage:[UIImage imageNamed:@"3.jpg"]];
    image.frame = CGRectMake(0, 0, 300, 300);
    image.center = self.view.center;
    [self.view addSubview:image];
    [image release];
}
#pragma mark - 知识点6: UIView的 transform 属性
/** 
 * TransForm 属性主要设置 view 的位置移动 缩放 旋转
 * 详见 ImageViewWithGesture 类
 */
#pragma mark - 屏幕边缘手势
- (void)createScreenEdgeGesture{
    UIScreenEdgePanGestureRecognizer *edg = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleedge:)];
    [self.view addGestureRecognizer:edg];
    [edg release];
    edg.edges = UIRectEdgeLeft;
}
- (void)handleedge:(UIScreenEdgePanGestureRecognizer *)ede{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
